﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Fanfou
{
    public class MessageTimeline
    {
        private int currentPage;
        private int messageCountPerPage;
        private int currentMaxId;
        private int currentMinId;

        public int CurrentPage
        {
            get
            {
                return currentPage;
            }
            set
            {
                currentPage = value;
            }
        }

        public int MessageCountPerPage
        {
            get
            {
                return messageCountPerPage;
            }
            set
            {
                messageCountPerPage = value;
            }
        }

        public int CurrentMaxId
        {
            get
            {
                return currentMaxId;
            }
            set
            {
                currentMaxId = value;
            }
        }

        public int CurrentMinId
        {
            get
            {
                return currentMinId;
            }
            set
            {
                currentMinId = value;
            }
        }

        public MessageTimeline()
        {
            this.CurrentMaxId = 4;
            this.CurrentMinId = 0;
            this.CurrentPage = 0;
            this.MessageCountPerPage = 5;
        }

        public MessageTimeline(int currentPage, int messageCountPerPage, int currentMinId, int currentMaxId)
        {
            this.CurrentMaxId = currentMaxId;
            this.CurrentMinId = currentMinId;
            this.CurrentPage = currentPage;
            this.MessageCountPerPage = messageCountPerPage;

            if (currentMaxId - currentMinId != messageCountPerPage - 1)
            {
                throw new IndexOutOfRangeException("Max ID - Min ID should equal with the message count per page");
            }
        }

        internal string ComposeTimeLineUrl()
        {
            if (this.CurrentPage == 0)
            {
                return ApiUrls.USER_TIMELINE + "?" + "count=" + this.MessageCountPerPage;
            }
            else
            {
                return ApiUrls.USER_TIMELINE + "?" + "count=" + this.MessageCountPerPage + "&since_id=" + this.CurrentMinId + "&max_id=" + this.CurrentMaxId;
            }            
        }
    }
}
